package com.hanxiaozhang.system.dao;

import com.hanxiaozhang.system.entity.UserDeptEntity;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 用户部门关联表
 *
 * @author hanxiaozhang
 * @email hanxiaozhang2018@sina.com
 * @date 2021-03-25
 */
@Mapper
public interface UserDeptDao {

	UserDeptEntity get(Long userDeptId);
	
	List<UserDeptEntity> list(Map<String, Object> map);

	int save(UserDeptEntity userDept);
	
	int update(UserDeptEntity userDept);

	int batchSave(List<UserDeptEntity> roleMenus);


    /**
     * 通过部门id查询
     *
     * @param deptId
     * @return
     */
	@Select("SELECT * FROM sys_user_dept WHERE dept_id = #{deptId} AND  del_flag=0")
	List<UserDeptEntity> listByDeptId(@Param("deptId") Long deptId);

    /**
     * 通过用户id查询
     *
     * @param userId
     * @return
     */
    @Select("SELECT * FROM sys_user_dept WHERE user_id = #{userId} AND  del_flag=0")
	List<UserDeptEntity> listByUserId(@Param("userId") Long userId);

    /**
     * 通过部门id集合查询
     *
     * @param deptIds
     * @return
     */
	List<UserDeptEntity> listByDeptIds(@Param("deptIds") List<Long> deptIds);

    /**
     * 通过用户id集合查询
     *
     * @param userIds
     * @return
     */
	List<UserDeptEntity> listByUserIds(@Param("userIds") List<Long> userIds);


    /**
     * 通过用户id删除
     *
     * @param userId
     * @return
     */
    @Update("UPDATE sys_user_dept SET del_flag = 1  WHERE user_id = #{userId} AND  del_flag = 0")
    int removeByUserId(@Param("userId") Long userId);


	/**
	 * 通过用户id集合批量删除
	 *
	 * @param userIds
	 * @return
	 */
	int batchRemoveByUserIds(Long[] userIds);

	
}
